import { GameMode, system, world } from "@minecraft/server";
import { GameComponent } from "@sapi-game/gameComponent";
import { EntityTypeIds } from "@sapi-game/utils/vanila-data";
import { HubState } from "../hubState";

export class HubArmorStandProtecter extends GameComponent<HubState> {
    protected override onAttach(): void {
        this.subscribe(world.beforeEvents.playerInteractWithEntity, (t) => {
            if (
                t.target.typeId == EntityTypeIds.ArmorStand &&
                t.player.getGameMode() != GameMode.Creative
            ) {
                if (this.state.region.isInside(t.player.location)) {
                    system.run(() => {
                        t.player.onScreenDisplay.setActionBar(
                            "你无法和盔甲架交互"
                        );
                    });
                    t.cancel = true;
                }
            }
        });
    }
}
